<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <span>{{ number }}</span><br>
        <button v-on:click="plus">加1</button>
        <button v-on:click="number = 1">重置</button>
        <hr>
        <p>Has published books:</p>
        <span>计算属性：{{ publishedBooksMessage }}</span><br> <!-- 有缓存 相对复杂，用的地方多，用这个mounted() {}-->
        <span>方法：{{ publishedBooksNumber() }}</span> <!-- 过程简单 用这个 methods: {}-->
    </div>
    <script src="https://unpkg.com/vue@next"></script>
    <script>
        const App = {
            data() {
                return {
                    numberL: 1,
                    author: {
                        name: 'John Doe',
                        books: [
                            'Vue 2 - Advanced Guide',
                            'Vue 3 - Basic Guide',
                            'Vue 4 - The Mystery'
                        ]
                    }
                }
            },
            mounted() {
                setInterval(() => {
                    this.author.books.push("ABCDEFG advanture")
                }, 1000)
            },
            methods: {
                publishedBooksNumber() {
                    // `this` 指向 vm 实例
                    return this.author.books.length
                }
            },
            computed: {
                // 计算属性的 getter
                publishedBooksMessage() {
                    // `this` 指向 vm 实例
                    return this.author.books.length
                }
            }
        }
        Vue.createApp(App).mount("#app")
    </script>
</body>

</html>